//
//  ThirdViewController.m
//  MvcTest
//
//  Created by SDMac on 15/5/11.
//  Copyright (c) 2015年 SDMac. All rights reserved.
//

#import "ThirdViewController.h"

#import "HZLAnnotation.h"

@interface ThirdViewController ()

@end

@implementation ThirdViewController
#pragma mark ---- life cycle

- (void)loadView
{
    UIView *view = [[UIView alloc]initWithFrame:ScreenBunds];
    
    self.view = view;
    
    self.view.backgroundColor = [UIColor grayColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.titleLabel.font = [UIFont systemFontOfSize:17];
    btn.frame = CGRectMake(0, ScreenBunds.size.height - 93, ScreenBunds.size.width, 44);
    btn.backgroundColor = [UIColor greenColor];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"First" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(getAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"第三";
    
    self.mapView=[[MAMapView alloc] initWithFrame:CGRectMake(0,64,320,ScreenBunds.size.height - 157)];
    self.mapView.delegate = self;
    self.mapView.mapType = MAMapTypeStandard;
    self.mapView.showTraffic = NO;
    self.mapView.showsCompass = YES;
    self.mapView.showsScale= YES;
    [self.mapView setZoomLevel:8 animated:NO];
    
    [self.view addSubview:self.mapView];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    RootViewController *root=(RootViewController *)self.tabBarController;
    [root setTabarHiend:NO];
    self.navigationController.navigationBarHidden=NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ---- UITableViewDelegate

#pragma mark - MAMapViewDelegate

- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
    //搜索周边执行方法
    if ([annotation isKindOfClass:[HZLAnnotation class]])
    {
        static NSString *poiIdentifier = @"poiIdentifier";
        
        MAPinAnnotationView *poiAnnotationView = (MAPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:poiIdentifier];
        
        if (!poiAnnotationView)
        {
            poiAnnotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:poiIdentifier];
        }
        
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        //[btn addTarget:self action:@selector(getbtnC) forControlEvents:UIControlEventTouchUpInside];
        
        poiAnnotationView.canShowCallout = YES;
        
        poiAnnotationView.rightCalloutAccessoryView =btn;
        
        return poiAnnotationView;
    }
    
    return nil;
}

#pragma mark ---- CustomDelegate

#pragma mark ---- event response

-(void)getAction:(UIButton*)sender
{
    NSMutableArray *detailsAry=[NSMutableArray arrayWithCapacity:4];
    
    HZLAnnotation *poiA = [[HZLAnnotation alloc] init];
    poiA.coordinate = CLLocationCoordinate2DMake(31.289292,121.453384);
    poiA.title = @"昆仑";
    poiA.subtitle = @"灵石路656号";
    [detailsAry addObject:poiA];
    
    HZLAnnotation *poiB = [[HZLAnnotation alloc] init];
    poiB.coordinate = CLLocationCoordinate2DMake(31.289438,121.454086);
    poiB.title = @"峨眉";
    poiB.subtitle = @"大宁路656号";
    [detailsAry addObject:poiB];
    
    HZLAnnotation *poiC = [[HZLAnnotation alloc] init];
    poiC.coordinate = CLLocationCoordinate2DMake(31.289253,121.452993);
    poiC.title = @"青城";
    poiC.subtitle = @"广中路656号";
    [detailsAry addObject:poiC];
    
    [self.mapView addAnnotations:detailsAry];
    
    [self.mapView showAnnotations:detailsAry animated:YES];
}

#pragma mark ---- private methods

#pragma mark ---- getters and setters

@end
